package com.auction.controller;

import com.auction.common.core.controller.MyBaseController;
import com.auction.common.utils.ReturnResult;
import com.auction.entity.Bidding;
import com.auction.service.BiddingService;
import com.auction.utils.PageBidding;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@Api(tags = "竞拍管理")
public class BiddingController extends MyBaseController {
    @Autowired
    private BiddingService biddingService;

    @PostMapping("/saveBidding")
    @ApiOperation("添加竞拍")
    public ReturnResult saveBidding(@RequestBody Bidding bidding) {
        int res=biddingService.saveEntity(bidding);
        return saveResult(res);
    }

    @PutMapping("/updateBidding")
    @ApiOperation("修改竞拍")
    public ReturnResult updateBidding(@RequestBody Bidding bidding) {
        int res=biddingService.updateEntity(bidding);
        return updateResult(res);
    }

    @DeleteMapping("/deleteBidding")
    @ApiOperation("删除竞拍")
    public ReturnResult deleteBidding(@RequestParam(value = "id") int id) {
        System.out.println("删除id==========="+id);
        int res = biddingService.deleteIsDel(id);
        return deleteResult(res);
    }

    @PostMapping("/getBidding")
    @ApiOperation("竞拍分页信息")
    public ReturnResult getBidding(@RequestBody PageBidding pageBidding) {
        int sign=pageBidding.getSign();
        if(sign==0){
        return success("竞拍信息",biddingService.getBiddingOrderByPrice(pageBidding));
        }else {
            return success("竞拍信息",biddingService.getBiddingOrderByTime(pageBidding));
        }
    }
}
